package com.zsc.edu.gateway.modules.iot.device.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import com.zsc.edu.gateway.modules.iot.product.repo.ProductRepository;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author zhuang
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeviceQuery {
    @Resource
    private ProductRepository productRepository;
    /**
     * 设备名称
     */
    public String name;

    /**
     * 客户ID
     */
    public String clientId;
    /**
     * 产品Id
     */
    public Long productId;

    /**
     * 设备状态
     */
    public Device.Status state;
    /**
     * 设态是否在线
     */
    public Boolean isOnline;


    public LambdaQueryWrapper<Device> wrapper() {
        LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(this.name), Device::getName, this.name);
        queryWrapper.eq(StringUtils.hasText(this.clientId), Device::getClientId, this.clientId);
        queryWrapper.eq(Objects.nonNull(this.productId), Device::getProductId, this.productId);
        queryWrapper.eq(Objects.nonNull(this.isOnline), Device::getOnline, this.isOnline);
        queryWrapper.eq(Objects.nonNull(this.state), Device::getState, this.state);
        return queryWrapper;
    }
}
